package edu.java.homework.hw09.exercises.salads.components;

import edu.java.homework.hw09.exercises.salads.products.EggProduct;

public class EggComponent {

    // --- Instance Variables --------------------------------------------------
    private EggProduct eggProduct = null;
    private double weight = 0.0d;

    private static final String PRODUCT_ARG_EXCEPTION = "EggProduct object is null-pointed.";
    private static final String WEIGHT_ARG_EXCEPTION = "The weight of the product could NOT be negative number.";

    // --- Constructors --------------------------------------------------------
    public EggComponent(EggProduct eggProduct) {
	this(eggProduct, 0);
    }

    public EggComponent(EggProduct eggProduct, double weight) {
	// check input parameters
	if (eggProduct == null) {
	    throw new IllegalArgumentException(PRODUCT_ARG_EXCEPTION);
	}
	if (weight < 0) {
	    throw new IllegalArgumentException(WEIGHT_ARG_EXCEPTION);
	}

	this.eggProduct = eggProduct;
	this.weight = weight;
    }

    // --- Getters and Setters -------------------------------------------------
    public EggProduct getEggProduct() {
	return eggProduct;
    }

    public void setEggProduct(EggProduct eggProduct) {
	// check input parameters
	if (eggProduct == null) {
	    throw new IllegalArgumentException(PRODUCT_ARG_EXCEPTION);
	}
	this.eggProduct = eggProduct;
    }

    public double getWeight() {
	return weight;
    }

    public void setWeight(double weight) {
	if (weight < 0) {
	    throw new IllegalArgumentException(WEIGHT_ARG_EXCEPTION);
	}
	this.weight = weight;
    }

    @Override
    public String toString() {
	return getEggProduct().toString() + ", price: "
		+ getEggProduct().getPrice() + ", weight: " + getWeight();
    }
}
